iOS 5 Programming Pushing the Limits by Rob Napier & Mugunth Kumar

iOS 5 Programming Pushing the Limits by Rob Napier & Mugunth Kumar

Author:Rob Napier & Mugunth Kumar
Language: eng
Format: epub
Publisher: Wiley
Published: 2011-11-21T16:00:00+00:00


ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:LOGIN_URL]];

[request setUsername:loginName];

[request setPassword:password];

[request setDelegate:self];

[request setDidFinishSelector:@selector(loginDone:)];

[request setDidFailSelector:@selector(loginFailed:)];

[self.networkQueue addOperation:request];

return self;

}

That completes your web service call. Now you should notify the caller, (which is usually the view controller) about the outcome of the web service call. You will use delegates for this.

Adding Delegates to the RESTEngine

For every web service call this RESTEngine class exposes two delegate methods, one for notifying a successful call and another for error notification. Usually this delegate is implemented by the view controller that calls the methods in the RESTEngine.

Another, arguably cleaner way to notify the caller is by using blocks. Blocks have their own advantages and drawbacks, as discussed in Chapter 16, which also covers when to use blocks and when to use delegates. In that chapter, you modify this RESTEngine to return data and errors using blocks.

1. Use the following code to add a delegate definition to your RESTEngine class:

Code showing the delegate in RESTEngine.h

@protocol RESTEngineDelegate <NSObject>

@optional

-(void) loginSucceeded:(NSString*) accessToken;

-(void) loginFailedWithError:(NSError*) error;

@end



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.